package xkafka

import (
	"fmt"

	"gitlab-tech.shruisong.cn/growth/go-common/pkg/utils"
)

const (
	WriterLogPrefix = "KafkaWriter"
	ReaderLogPrefix = "KafkaReader"
)

type Logger interface {
	Infof(string, ...interface{})
	Errorf(string, ...interface{})
}

type DefaultLogger struct {
	prefix string
}

func (logger *DefaultLogger) SetPrefix(prefix string) {
	logger.prefix = prefix
}

func (logger *DefaultLogger) Infof(msg string, data ...interface{}) {
	message := fmt.Sprintf(msg, data...)
	message = fmt.Sprintf("%s %s", logger.prefix, message)
	utils.Log().Info(message)
}

func (logger *DefaultLogger) Errorf(msg string, data ...interface{}) {
	message := fmt.Sprintf(msg, data...)
	message = fmt.Sprintf("%s err: %s", logger.prefix, message)
	utils.Log().Error(message)
}
